/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.InputStream;
import java.util.Properties;

/**
 * <p>Project: jse2204 - DbDemo
 * <p>Powered by webrx On 2022-10-11 09:18:41
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class DbDemo {
    public static void main(String[] args) {
        //如何加载，maven项目中的src/main/resources目录下的配置文件 properties xml yaml

        //InputStream is = DbDemo.class.getClassLoader().getResourceAsStream("jdbc.properties");
        //System.out.println(is);

        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("jdbc.properties");
        //System.out.println(is);

        Properties prop = new Properties();
        try{
            prop.load(is);
            System.out.println(prop.get("user"));
            System.out.println(prop.getProperty("driver"));
            System.out.println(prop.getProperty("password","root"));

            //遍历properties文件所有
            prop.forEach((k,v)->{
                System.out.println(k);
                System.out.println(v);
            });
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
